{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "03a9606a",
   "metadata": {},
   "outputs": [],
   "source": [
    "* 本周主要内容：图像识别（人脸识别）\n",
    "* 日期：2023-03-013-week04\n",
    "* 记录人：姚远航"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9f2ae9b",
   "metadata": {},
   "source": [
    "# 上周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bbaaa03",
   "metadata": {},
   "source": [
    ">  1.API文档阅读（考试）              \n",
    ">  2. requests模块（考试）           \n",
    ">  3.百度通用图像识别              "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90f2a7f1",
   "metadata": {},
   "source": [
    "## 本周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9383a87",
   "metadata": {},
   "source": [
    "## 1.人脸识别概念和基础               \n",
    "## 2.人脸识别应用           \n",
    "## 3.人脸识别实践-face++     \n",
    ">1.人脸检测       \n",
    ">2.人脸识别应用     \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d8d0e32",
   "metadata": {},
   "source": [
    "## 人脸识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "732d93cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "90353e09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679557,f74c9b67-1046-4c4d-aaf1-03bb4116864e', 'time_used': 293, 'faces': [{'face_token': '29b15f68bfbd8e883f6f6c6bf7882c32', 'face_rectangle': {'top': 314, 'left': 195, 'width': 449, 'height': 449}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 19}, 'smile': {'value': 0.013, 'threshold': 50.0}, 'headpose': {'pitch_angle': 0.89773107, 'roll_angle': -17.910566, 'yaw_angle': 13.546975}, 'blur': {'blurness': {'value': 0.034, 'threshold': 50.0}, 'motionblur': {'value': 0.034, 'threshold': 50.0}, 'gaussianblur': {'value': 0.034, 'threshold': 50.0}}, 'facequality': {'value': 67.373, 'threshold': 70.1}}}], 'image_id': 'Y5JXdckGIKWTvqmmXr9/TA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.\n",
    "f = open('D:/API学习/api/week04/wyf.jpg','rb')\n",
    "img = base64.b64encode(f.read())\n",
    "#2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'PLyz3qFkk5VigBhtbVRH0O6tTU_LDcDN',\n",
    "    'api_secret':'CLhFqVzrLbuIEBpKaiejCFneU2Yon_HT',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur'\n",
    "}\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
